package com.yc.controller;


import com.yc.entity.Record;
import com.yc.mapper.RecordMapper;
import com.yc.service.IRecordService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Arrays;
import java.util.List;

/**
 * <p>
 * InnoDB free: 4096 kB 前端控制器
 * </p>
 *
 * @author zzw
 * @since 2022-06-18
 */
@Controller
@RequestMapping("//record")
public class RecordController {
    @Resource
    private RecordMapper recordMapper;
    @Resource
    private IRecordService recordService;

    @RequestMapping("queryByUid")
    @ResponseBody
    public List< Record > queryByUid(Integer uid){
        return recordMapper.queryByUid(uid);
    }

    @RequestMapping("addRecord")
    @ResponseBody
    public Integer addRecord(Integer uid,Integer ctid,Integer pid){
        return recordService.addRecord(uid, ctid, pid);
    }

    @RequestMapping("deleteByRcid")
    @ResponseBody
    public Integer deleteByRcid(Integer rcid){
        return recordMapper.deleteByRcid(rcid);
    }

    @RequestMapping("deleteByRcidList")
    @ResponseBody
    public Integer deleteByRcidList(@RequestBody Integer[] rcids){
        List rcidlist= Arrays.asList(rcids);
        return recordService.deleteByRcidList(rcidlist);
    }

    @RequestMapping("deleteAllPlays")
    @ResponseBody
    public Integer deleteAllPlays(Integer uid){
        return recordMapper.deleteAllPlays(uid);
    }

    @RequestMapping("queryByUidAndCtid")
    @ResponseBody
    public List<Record> queryByUidAndCtid(Integer uid,Integer ctid){
        return recordMapper.queryByUidAndCtid(uid, ctid);
    }

    @RequestMapping("updateRecord")
    @ResponseBody
    public Integer updateRecord(@RequestBody Record record, Integer pid){
        return recordService.updateRecord(record,pid);
    }
}

